From: Marco Trevisan (TreviƱo) Date: Wed, 29 Apr 2026 17:06:43 +0000 (+0200) Subject: status/network: Tie wireless network items to their network X-Git-Tag: archive/raspbian/50.5-1+rpi1^2~6^2^2~12 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=d838bf816a863b786760307a487d3250b5104514;p=gnome-shell.git status/network: Tie wireless network items to their network We were using a map to control the wireless networks and relate them to the associated item, although we did not clean it up fully on destruction. So rather than handling the manual removal of the items bound to a wireless network, tie them to the network destruction itself. This allows to simplify the removal of an access point, by just destroying its network and to avoid using a sub-utilized Map. Part-of: (cherry picked from commit 51f2d834395d1066b54a33d32d487e1716fd8943) --- diff --git a/js/ui/status/network.js b/js/ui/status/network.js index 4c28690b3..1bc9d402a 100644 --- a/js/ui/status/network.js +++ b/js/ui/status/network.js @@ -1083,7 +1083,7 @@ const NMWirelessDeviceItem = GObject.registerClass({ this._deviceName = ''; - this._networkItems = new Map(); + this._networks = []; this._itemSorter = new ItemSorter({ sortFunc: (one, two) => one.network.compare(two.network), }); @@ -1124,10 +1124,8 @@ const NMWirelessDeviceItem = GObject.registerClass({ this._availableConnectionsChanged(); this._updateItemsVisibility(); - this.connect('destroy', () => { - for (const net of this._networkItems.keys()) - net.destroy(); - }); + this.connect('destroy', + () => this._networks.forEach(net => net.destroy())); } get icon_name() { @@ -1219,8 +1217,7 @@ const NMWirelessDeviceItem = GObject.registerClass({ _availableConnectionsChanged() { const connections = this._device.get_available_connections(); - for (const net of this._networkItems.keys()) - net.checkConnections(connections); + this._networks.forEach(net => net.checkConnections(connections)); } _addAccessPoint(ap) { @@ -1236,8 +1233,7 @@ const NMWirelessDeviceItem = GObject.registerClass({ return; } - let network = [...this._networkItems.keys()] - .find(n => n.checkAccessPoint(ap)); + let network = this._networks.find(n => n.checkAccessPoint(ap)); if (!network) { network = new WirelessNetwork(this._device); @@ -1248,28 +1244,30 @@ const NMWirelessDeviceItem = GObject.registerClass({ network.connectObject( 'notify::icon-name', () => this._resortItem(item), 'notify::is-active', () => this._resortItem(item), + 'destroy', () => { + const idx = this._networks.indexOf(network); + if (idx >= 0) + this._networks.splice(idx, 1); + + this._itemSorter.delete(item); + item.destroy(); + }, this); const pos = this._itemSorter.upsert(item); this.section.addMenuItem(item, pos); - this._networkItems.set(network, item); + this._networks.push(network); } network.addAccessPoint(ap); } _removeAccessPoint(ap) { - const network = [...this._networkItems.keys()] - .find(n => n.removeAccessPoint(ap)); + const network = this._networks.find(n => n.removeAccessPoint(ap)); if (!network || network.hasAccessPoints()) return; - const item = this._networkItems.get(network); - this._itemSorter.delete(item); - this._networkItems.delete(network); - - item?.destroy(); network.destroy(); }